#include<iostream>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<string.h>

#define ERR_EIXT(m) \
do{\
    perror(m);\
    exit(EXIT_FAILURE);\
}while(0)

int main(){
    FILE* fp = fopen("OriginalFile.txt","r");
    if (!fp) ERR_EIXT("Error opening OriginalFile.txt");

    int r=mkfifo("myfifo", 0666);
    if(r==-1){ 
        ERR_EIXT("Error creating myfifo.txt");
        fclose(fp);
        return 1;
    }

    FILE* fifop=fopen("myfifo","w");
    if(!fifop){
        ERR_EIXT("Error opening myfifo");
        fclose(fp);
        return 1;
    }

    char buffer[100]={0};
    if(fgets(buffer,sizeof(buffer)-1,fp)){
        fwrite(buffer,sizeof(char),strlen(buffer),fifop);
    }
    else{
        ERR_EIXT("Error getting character from fp");
        fclose(fp);
        return 1;
    }

    fclose(fp);
    return 0;
}